<?php
if (!defined('DC_CONTEXT_ADMIN')) exit;
if (!$core->auth->check('agenda', $core->blog->id)) exit;
require_once dirname(__FILE__).'/class.dc.agendaPlugin.php';
require_once dirname(__FILE__).'/class.dc.agendaList.php';
require_once dirname(__FILE__).'/lib.agenda.page.php';
$agenda = new dcAgendaPlugin($core);

if (isset($_REQUEST['newpage'])){
	include dirname(__FILE__)."/newevent.php";
}else{
	$combo_action = array();
	if ($core->auth->check('publish,contentadmin',$core->blog->id))
	{
		$combo_action[__('publish')] = 'publish';
		$combo_action[__('unpublish')] = 'unpublish';
	}
	if ($core->auth->check('delete,contentadmin',$core->blog->id))
	{
		$combo_action[__('delete')] = 'delete';
	}
	# --BEHAVIOR-- adminPagesActionsCombo
	$core->callBehavior('adminPagesActionsCombo',array(&$combo_action));
	$page = !empty($_GET['page']) ? $_GET['page'] : 1;
	$nb_per_page =  30;
	
	if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
		if ($nb_per_page != $_GET['nb']) {
			$show_filters = true;
		}
		$nb_per_page = (integer) $_GET['nb'];
	}
	
	$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
	$params['no_content'] = true;
	$params['post_type'] = 'agenda';
	//$params['post_type'] = 'page';
	# Get pages
	try {
		$pages = $agenda->getPosts($params);
		//$pages->extend("rsRelated");
		$counter = $agenda->getPosts($params,true);
		$page_list = new agendaList($core,$pages,$counter->f(0));
	} catch (Exception $e) {
		$core->error->add($e->getMessage());
	}
	 ?>
	
	<html>
	<head>
	<title><?php echo __('Agenda Plugin'); ?></title>
	<?php
			echo
			dcPage::jsToolMan().
			dcPage::jsPageTabs($default_tab).
			dcPage::jsLoad('index.php?pf=agenda/_agenda.js');
			?>
	 <script type="text/javascript" src="js/_posts_list.js"></script>
	</head>
	<body>
	<h2><?php echo html::escapeHTML($core->blog->name); ?> &gt; <?php echo __('Agenda'); ?></h2>
	<?php if (!empty($msg)) echo '<p class="message">'.$msg.'</p>'; ?>
		<div class="multi-part" id="agenda_manage" title="<?php echo __('Manage events')?>">
			<p><a href="plugin.php?p=agendaPlugin&amp;newpage=-1"><?php echo __('Add New Event'); ?></a></p>
			<?php
			$page_list->display($page,$nb_per_page,
				//'<form action="plugin.php?p=agendaPlugin" method="post" id="form-pages" '.
				'<form action="posts_actions.php" method="post" id="form-entries">'.
				'%s'.
				'<div class="two-cols">'.
				'<p class="col checkboxes-helpers"></p>'.
				'<p class="col right">'.__('Selected events action:').
				form::combo('action',$combo_action).
				'<input type="submit" value="'.__('ok').'" /></p>'.
				form::hidden(array('post_type'),'agenda').
				form::hidden(array('redir'),html::escapeHTML($_SERVER['REQUEST_URI'])).
				$core->formNonce().
				'</div>'.
				'</form>', $url
			); 
			 ?>
		</div>
		<!-- <div  class="multi-part" id="agenda_todo" title="<?php //echo __('todo')?>"> -->
		<?php
			//include dirname(__FILE__).'/todo.html';
		?>
		<!--   </div>-->
		<div  class="multi-part" id="agenda_documentation" title="<?php echo __('Développement')?>">
                <?php
		 include dirname(__FILE__).'/documentation.html';
		?>
		</div>

	</body>
	</html>
<?php } // fin du else new page ?>
